//
//  THTimeCell.m
//  TaiHaoCloud
//
//  Created by rzm on 16/6/14.
//  Copyright © 2016年 rzm. All rights reserved.
//

#import "SmapuxTimeViewListCell.h"
#import "SPTimeValue.h"

@interface SmapuxTimeViewListCell ()

@property (nonatomic, strong) NSMutableArray *subArr;

@end

@implementation SmapuxTimeViewListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = THSystemClearColor;
        _subArr = [NSMutableArray array];
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView
{
    CGFloat font = 8.;
    if (IS_IPHONE_4_OR_LESS) {
        font = 14.;
    }else if (IS_IPHONE_5_OR_LESS)
    {
        font = 16.;
    }else if (IS_IPHONE_6)
    {
        font = 18.;
    }else
    {
        font = 18.;
    }
    _weeklab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth , Sampux6HScale(30))];
    _weeklab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_weeklab];
    _weeklab.backgroundColor = THWhiteAlplaColor(0.2);
    _weeklab.textColor = THSystemWhiteColor;
    _weeklab.font = THFont(font);
    
    UIImageView *arrowImg = [[UIImageView alloc]initWithFrame:CGRectMake(self.width/2 + Sampux6WScale(90),  Sampux6HScale(30)/2 -  Sampux6HScale(27/2)/2, Sampux6WScale(7), Sampux6HScale(27/2))];
    arrowImg.image = imageNamed(@"arrow-1");
    [self addSubview:arrowImg];

    NSArray *arr =@[@"morning_x",@"noon_x",@"after_x",@"night_x"];
    for (int i = 0; i < 4; i ++)
    {
        SampuxTimeViewListCellSub *subView  = [[SampuxTimeViewListCellSub alloc]initWithFrame:CGRectMake(0, i * Sampux6HScale(44) + CGRectGetMaxY(_weeklab.frame) , kScreenWidth, Sampux6HScale(44))];
        [self addSubview:subView];
        subView.backgroundColor = THSystemClearColor;
        subView.tag = i + 100;
        subView.timeLabel.text = @"dfdf";
        [_subArr addObject:subView];

        [subView.timeImg setImage:imageNamed(arr[i]) forState:UIControlStateNormal];
        if (i == 3) {
            subView.line.hidden = YES;
        }
    }

}

- (void)setModel:(SampuxInstallTimeModel *)model
{
    _model = model;
//    
//    NSArray *arr = [NSArray arrayWithObjects:_model.onePoint,_model.twoPoint,_model.threePoint,_model.fourPoint, nil];
    
    NSArray *arr = [NSArray arrayWithObjects:[SPTimeValue setTimeValue:_model.onePoint],[SPTimeValue setTimeValue:_model.twoPoint],[SPTimeValue setTimeValue:_model.threePoint],[SPTimeValue setTimeValue:_model.fourPoint], nil];

    NSArray *speed =[NSArray arrayWithObjects:_model.oneValue,_model.twoValue,_model.threeValue,_model.fourValue,nil];
    for (int i = 0; i < _subArr.count; i ++) {
        SampuxTimeViewListCellSub *sub = _subArr[i];
        sub.timeLabel.text = arr[i];
        sub.speedLabel.text = [NSString stringWithFormat:@"%@℃",speed[i]];
    }
//     NSArray *arr = @[_model.timeText_morning,_model.timeText_noon,_model.timeText_after,_model.timeText_night];
//    NSArray *speed = @[_model.speedText_morning,_model.speedText_noon,_model.speedText_after,_model.speedText_night];
//    for (int i = 0; i < _subArr.count; i ++) {
//        SampuxTimeViewListCellSub *sub = _subArr[i];
//        sub.timeLabel.text = arr[i];
//        sub.speedLabel.text = speed[i];
//
//    }
   

}

@end
